package cn.xenosp.server.common.tools;

import cn.hutool.core.date.DateUtil;
import org.springframework.scheduling.support.CronExpression;

import java.time.LocalDateTime;

/**
 * 项目名： service-web
 * 包路径： cn.xenosp.server.common.tools
 * 作者：   TongHui
 * 创建时间: 2025-11-25 13:42
 * 描述: TODO
 * 版本: 1.0
 */
public class CronUtil {

    public static String[] getCron(String cron,int next){
        String[] cronArr = new String[next];
        CronExpression cronExpression = CronExpression.parse(cron);
        LocalDateTime now = LocalDateTime.now();
        for (int i = 0; i < next; i++) {
            LocalDateTime nextExecution = cronExpression.next(now);
            cronArr[i]= DateUtil.formatLocalDateTime(nextExecution);
            now = nextExecution;
        }
        return cronArr;
    }
}
